#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：python常用模块库 
@File ：单进程使用.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2025/2/20 上午1:07 
"""

from shared_memory import SharedMemory

# 创建并使用共享内存
memory_name = "/shm_test"
memory_size = 1024  # 1KB

# 写入数据
with SharedMemory(memory_name, memory_size, create=True) as shm:
	data = {"message": "Hello, Shared Memory!"}
	shm.write(data)

# 读取数据
with SharedMemory(memory_name, memory_size, create=False) as shm:
	result = shm.read()
	print(f"Read from shared memory: {result}")

# 清理共享内存
shm = SharedMemory(memory_name, memory_size, create=False)
shm.close()
shm.unlink()
